package com.haixiaoke.saas.enterprise.menu.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.haixiaoke.saas.common.annotation.Log;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.enums.BusinessType;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.menu.domain.BizMenu;
import com.haixiaoke.saas.menu.service.IBizMenuService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 企业端菜单权限Controller
 * 
 * @author panda
 * @date 2023-12-29
 */
@RestController
@RequestMapping("/enterprise/menu/menu")
public class EnterpriseBizMenuController extends BaseController {
    @Autowired
    private IBizMenuService bizMenuService;

    /**
     * 查询企业端菜单权限列表
     */
    @PreAuthorize("@ss.hasPermi('business:menu:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizMenu bizMenu) {
        startPage();
        bizMenu.setUserId(getUserId());
        List<BizMenu> list = bizMenuService.selectBizMenuList(bizMenu);
        return getDataTable(list);
    }

    /**
     * 导出企业端菜单权限列表
     */
    @PreAuthorize("@ss.hasPermi('business:menu:export')")
    @Log(title = "企业端菜单权限", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizMenu bizMenu) {
        List<BizMenu> list = bizMenuService.selectBizMenuList(bizMenu);
        ExcelUtil<BizMenu> util = new ExcelUtil<BizMenu>(BizMenu.class);
        util.exportExcel(response, list, "企业端菜单权限数据");
    }

    /**
     * 获取企业端菜单权限详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:menu:query')")
    @GetMapping(value = "/{menuId}")
    public AjaxResult getInfo(@PathVariable("menuId") Long menuId) {
        return success(bizMenuService.selectBizMenuByMenuId(menuId));
    }

    /**
     * 新增企业端菜单权限
     */
    @PreAuthorize("@ss.hasPermi('business:menu:add')")
    @Log(title = "企业端菜单权限", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizMenu bizMenu) {
        return toAjax(bizMenuService.insertBizMenu(bizMenu));
    }

    /**
     * 修改企业端菜单权限
     */
    @PreAuthorize("@ss.hasPermi('business:menu:edit')")
    @Log(title = "企业端菜单权限", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizMenu bizMenu) {
        return toAjax(bizMenuService.updateBizMenu(bizMenu));
    }

    /**
     * 删除企业端菜单权限
     */
    @PreAuthorize("@ss.hasPermi('business:menu:remove')")
    @Log(title = "企业端菜单权限", businessType = BusinessType.DELETE)
	@DeleteMapping("/{menuIds}")
    public AjaxResult remove(@PathVariable Long[] menuIds) {
        return toAjax(bizMenuService.deleteBizMenuByMenuIds(menuIds));
    }
}
